package com.digitalchina.lxnsy.activity.old;

import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import androidx.annotation.NonNull;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.alibaba.fastjson.JSON;
import com.bigkoo.pickerview.OptionsPickerView;
import com.bigkoo.pickerview.TimePickerView;
import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.api.BusinessActivity;
import com.digitalchina.lxnsy.api.BusinessFile;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.constant.MSG;
import com.digitalchina.lxnsy.entity.ActivityListVO;
import com.digitalchina.lxnsy.entity.ActivityTypeVO;
import com.digitalchina.lxnsy.entity.FileVO;
import com.digitalchina.lxnsy.entity.ImageVO;
import com.digitalchina.lxnsy.loader.GlideImageLoader;
import com.digitalchina.lxnsy.toolkit.DateStyle;
import com.digitalchina.lxnsy.toolkit.FastJsonUtil;
import com.digitalchina.lxnsy.toolkit.FrescoUtil;
import com.digitalchina.lxnsy.toolkit.StringUtil;
import com.digitalchina.lxnsy.toolkit.Utils;
import com.digitalchina.lxnsy.widget.EditTextWithClear;
import com.facebook.drawee.view.SimpleDraweeView;
import com.lzy.imagepicker.ImagePicker;
import com.lzy.imagepicker.bean.ImageItem;
import com.lzy.imagepicker.ui.ImageGridActivity;

import org.json.JSONException;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import chihane.jdaddressselector.BottomDialog;
import chihane.jdaddressselector.OnAddressSelectedListener;
import chihane.jdaddressselector.model.City;
import chihane.jdaddressselector.model.County;
import chihane.jdaddressselector.model.Province;
import chihane.jdaddressselector.model.Street;

import static com.digitalchina.lxnsy.toolkit.DateUtil.DateToString;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：发布活动页面
 * 包名：com.digitalchina.bigdata.activity
 * 创建人：郑皓
 * 创建时间：2018/7/12 15:13
 * 修改备注：
 * ================================================
 */
public class AddActivityActivity extends BaseActivity {

    @Bind(R.id.et_name)
    EditTextWithClear etName;
    @Bind(R.id.tv_type)
    TextView tvType;
    @Bind(R.id.rb_reservation_no)
    RadioButton rbReservationNo;
    @Bind(R.id.rb_reservation_yes)
    RadioButton rbReservationYes;
    @Bind(R.id.rg_reservation)
    RadioGroup rgReservation;
    @Bind(R.id.tv_start_date)
    TextView tvStartDate; // registerStartTime 报名开始时间
    @Bind(R.id.tv_end_date)
    TextView tvEndDate;  // registerDeadline 报名结束时间
    @Bind(R.id.tv_start_date_process)
    TextView tvStartDateProcess;
    @Bind(R.id.tv_end_date_process)
    TextView tvEndDateProcess;
    @Bind(R.id.tv_area)
    TextView tvArea;
    @Bind(R.id.et_detail_address)
    EditTextWithClear etDetailAddress;
    @Bind(R.id.rb_price_no)
    RadioButton rbPriceNo;
    @Bind(R.id.rb_price_yes)
    RadioButton rbPriceYes;
    @Bind(R.id.rg_price)
    RadioGroup rgPrice;
    @Bind(R.id.et_price)
    EditTextWithClear etPrice;
    @Bind(R.id.rb_people_no)
    RadioButton rbPeopleNo;
    @Bind(R.id.rb_people_yes)
    RadioButton rbPeopleYes;
    @Bind(R.id.rg_people)
    RadioGroup rgPeople;
    @Bind(R.id.et_num)
    EditTextWithClear etNum;
    @Bind(R.id.et_zbf_name)
    EditTextWithClear etZbfName;
    @Bind(R.id.et_zbf_contacts)
    EditTextWithClear etZbfContacts;
    @Bind(R.id.et_zbf_tel)
    EditTextWithClear etZbfTel;
    @Bind(R.id.et_cbf_name)
    EditTextWithClear etCbfName;
    @Bind(R.id.et_cbf_contacts)
    EditTextWithClear etCbfContacts;
    @Bind(R.id.et_cbf_tel)
    EditTextWithClear etCbfTel;
    @Bind(R.id.iv_img)
    SimpleDraweeView ivImg;
    @Bind(R.id.et_info)
    TextView etInfo;
    @Bind(R.id.btn_save)
    Button btnSave;
    @Bind(R.id.layout_reservation)
    LinearLayout layoutReservation; // 报名时间布局
    @Bind(R.id.layout_price)
    LinearLayout layoutPrice; // 价格输入布局
    @Bind(R.id.layout_num)
    LinearLayout layoutNum; // 限制人数布局
    @Bind(R.id.tv_where)
    TextView tvWhere;
    @Bind(R.id.rl_choose_zone)
    RelativeLayout rlChooseZone;
    @Bind(R.id.tv_detail)
    TextView tvDetail;
    @Bind(R.id.sdv_img0)
    SimpleDraweeView sdvImg0;
    @Bind(R.id.sdv_img1)
    SimpleDraweeView sdvImg1;
    @Bind(R.id.sdv_img2)
    SimpleDraweeView sdvImg2;
    @Bind(R.id.sdv_img3)
    SimpleDraweeView sdvImg3;
    @Bind(R.id.sdv_img4)
    SimpleDraweeView sdvImg4;
    @Bind(R.id.sdv_img5)
    SimpleDraweeView sdvImg5;
    @Bind(R.id.sdv_img6)
    SimpleDraweeView sdvImg6;
    @Bind(R.id.sdv_img7)
    SimpleDraweeView sdvImg7;


    private String activityName = "";//   活动名称
    private String code = "";// 活动类型code
    private String isRegister = "0";// 活动是否需要报名 0 不需要 1 需要  默认0
    private String registerStartTime = "";//活动报名开始时间
    private String registerDeadline = "";// 活动报名截止时间
    private String startTime = "";// 活动开始时间
    private String endTime = "";// 活动截止时间
    private String provinceName = "";// 省名称
    private String cityName = "";// 市名称
    private String countyName = "";// 区县名称
    private String provinceNameCode = "";// 省名称
    private String cityNameCode= "";// 市名称
    private String countyNameCoee = "";// 区县名称


    private String address = "";// 详细地址
    private String isFee = "0";// 是否收费 0:免费 1 收费 默认0
    private String fee = "";// 费用价格
    private String isLimit = "0";// 是否限制人数 0 不限 1 限制 默认0
    private String num = "";// 活动人数

    private String sponsorName = "";//主办方名称
    private String sponsorPerson = "";//主办方联系人
    private String sponsorTel = "";//主办方联系方式
    private String organizerName = "";// 承办方名称
    private String organizerPerson = "";//承办方联系人
    private String organizerTel = "";//承办方联系方式
    private String imgPath = "";// 海报
    private String activityId = "";//有值为修改

    private String activityIntroduce = "";// 活动介绍
    //    private List<ImageVO> imageVOList = new ArrayList<>(); // 图片list
    private String subjectActivityDescImageList = ""; // 图片json集合


    // 图片
    public static final int IMAGE_ITEM_ADD = -1;
    public static final int REQUEST_CODE_SELECT = 100;
    public static final int REQUEST_CODE_PREVIEW = 101;
//    private ImagePickerAdapter imagePickerAdapter;
//    private ArrayList<ImageItem> selectedImageList; //当前选择的所有图片
//    private int maxImgCount = 8;               //允许选择图片最大数
//    private List<String> filePath = new ArrayList<>(); // 图片地址

    private int imgNum = 0;
    private int select = -1; // -1为上传主图  其他上传详情图
    private String[] imgs = {"", "", "", "", "", "", "", ""};
    private SimpleDraweeView[] sdvArray = new SimpleDraweeView[8];


    private OptionsPickerView pvActivityType;
    private List<ActivityTypeVO> typeList = new ArrayList<>();

    // 时间选择器
    private TimePickerView pvTime;
    private int type = 0;

    // 图片
    public static final int REQUEST_CODE_SELECT_POSTER = 102;
    //    private ArrayList<ImageItem> posterList = new ArrayList<>(); //海报
    private String posterPath = ""; // 图片地址


    @Override
    public void setLayout() {
        setContentLayout(R.layout.activity_add_activity);
        setTitle("发布活动");
    }

    @Override
    public void initMember() {

        initData();

        // 活动类型
        BusinessActivity.getActivityType(this, mHandler);

        initTimePicker();

        if (getIntent() != null && getIntent().hasExtra("editActivity"))
            setValue();



    }

    // 初始化数据
    private void initData() {
        selectImage();


        sdvArray[0] = sdvImg0;
        sdvArray[1] = sdvImg1;
        sdvArray[2] = sdvImg2;
        sdvArray[3] = sdvImg3;
        sdvArray[4] = sdvImg4;
        sdvArray[5] = sdvImg5;
        sdvArray[6] = sdvImg6;
        sdvArray[7] = sdvImg7;
    }

    private void selectImage() {
        ImagePicker imagePicker = ImagePicker.getInstance();
        imagePicker.setImageLoader(new GlideImageLoader());   //设置图片加载器
        imagePicker.setShowCamera(true);  //显示拍照按钮
        imagePicker.setMultiMode(false);    //是否多选模式
        imagePicker.setCrop(false);        //允许裁剪（单选才有效）
    }

    // 修改活动 则回填数据
    private void setValue() {
        ActivityListVO vo = (ActivityListVO) getIntent().getSerializableExtra("editActivity");

        if (vo == null)
            return;

        activityId = vo.getId(); // 活动ID
        activityName = vo.getActivityName();//   活动名称
        code = vo.getType().code;// 活动类型code
        isRegister = vo.getIsRegister();// 活动是否需要报名 0 不需要 1 需要  默认0
        if (isRegister.equals("0")) {    // 是否报名
            layoutReservation.setVisibility(View.GONE);
            rbReservationNo.setChecked(true);
        } else {
            layoutReservation.setVisibility(View.VISIBLE);
            registerStartTime = vo.getRegisterStartTime(); // 报名开始时间
            registerDeadline = vo.getRegisterDeadline(); // 报名结束时间
            rbReservationYes.setChecked(true);
            tvStartDate.setText(registerStartTime + "");
            tvEndDate.setText(registerDeadline + "");
        }

        startTime = vo.getStartTime();// 活动开始时间
        endTime = vo.getEndTime();// 活动截止时间
        provinceName = vo.getProvince().provinceName;// 省名称
        cityName = vo.getCity().cityName;// 市名称
        countyName = vo.getCounty().countyName;// 区县名称

        provinceNameCode = vo.getProvince().provinceCode;// 省名称
        cityNameCode = vo.getCity().cityCode;// 市名称
        countyNameCoee = vo.getCounty().countyCode;// 区县名称
        if (StringUtil.isStrEmpty(provinceName))
            provinceName = "";
        if (StringUtil.isStrEmpty(cityName))
            cityName = "";
        if (StringUtil.isStrEmpty(countyName))
            countyName = "";
        address = vo.getAddress();// 详细地址
//        activityIntroduce = "";// 活动介绍 暂无
        sponsorName = vo.getSponsorName();//主办方名称
        sponsorPerson = vo.getSponsorPerson();//主办方联系人
        sponsorTel = vo.getSponsorTel();//主办方联系方式
        organizerName = vo.getOrganizerName();// 承办方名称
        organizerPerson = vo.getOrganizerPerson();//承办方联系人
        organizerTel = vo.getOrganizerTel();//承办方联系方式
        imgPath = vo.getImgPath();// 海报

        etName.setText(activityName + "");
        tvType.setText(vo.getType().name + ""); // 活动类型Name
        tvStartDateProcess.setText(startTime + ""); // 活动开始时间
        tvEndDateProcess.setText(endTime + ""); // 活动截止时间
        tvArea.setText(String.format("%s %s %s", provinceName, cityName
                , countyName));
        etDetailAddress.setText(address + "");

        isFee = vo.getIsFee();// 是否收费 0:免费 1 收费 默认0
        if (isFee.equals("0")) {
            layoutPrice.setVisibility(View.GONE);
            rbPriceNo.setChecked(true);
        } else {
            layoutPrice.setVisibility(View.VISIBLE);
            rbPriceYes.setChecked(true);
            fee = vo.getFee();
            etPrice.setText(fee + "");
        }

        isLimit = vo.getIsLimit();// 是否限制人数 0 不限 1 限制 默认0
        if (isLimit.equals("0")) {
            layoutNum.setVisibility(View.GONE);
            rbPeopleNo.setChecked(true);
        } else {
            layoutNum.setVisibility(View.VISIBLE);
            rbPeopleYes.setChecked(true);
            num = vo.getNum()+"";

            etNum.setText(num + "");
        }

        etZbfName.setText(sponsorName + "");
        etZbfContacts.setText(sponsorPerson + "");
        etZbfTel.setText(sponsorTel + "");

        if (!StringUtil.isStrEmpty(organizerName))
            etCbfName.setText(organizerName);
        if (!StringUtil.isStrEmpty(organizerPerson))
            etCbfContacts.setText(organizerPerson);
        if (!StringUtil.isStrEmpty(organizerTel))
            etCbfTel.setText(organizerTel);

        FrescoUtil.showImageSmall(imgPath, ivImg);

        etInfo.setText(vo.getActivityIntroduce() + "");


        if (vo.getImgPath() != null) {
            String[] imgList = vo.getImgPath().split(",");
            for (int i = 0; i < imgList.length; i++) {
                String img = imgList[i];
                imgs[i] = img;
                FrescoUtil.showImageSmall(img, sdvArray[i]);
            }
        }

    }

    @Override
    public void addListener() {

        // 是否有报名
        rgReservation.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (radioGroup.getCheckedRadioButtonId() == R.id.rb_reservation_no) {
                    isRegister = "0";
                    layoutReservation.setVisibility(View.GONE);
                } else {
                    isRegister = "1";
                    layoutReservation.setVisibility(View.VISIBLE);
                }
            }
        });

        // 是否免费
        rgPrice.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (radioGroup.getCheckedRadioButtonId() == R.id.rb_price_no) {
                    isFee = "0";
                    layoutPrice.setVisibility(View.GONE);
                } else {
                    isFee = "1";
                    layoutPrice.setVisibility(View.VISIBLE);
                }
            }
        });
        // 是否有限制人数
        rgPeople.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if (radioGroup.getCheckedRadioButtonId() == R.id.rb_people_no) {
                    isLimit = "0";
                    layoutNum.setVisibility(View.GONE);
                } else {
                    isLimit = "1";
                    layoutNum.setVisibility(View.VISIBLE);
                }
            }
        });

    }


    @Override
    public void setHandler() {
        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);

                switch (msg.what) {
                    case MSG.MSG_GET_ACTIVITY_TYPE_SUCCESS: // 活动类型
                        callBack(msg.obj);
                        break;
                    case MSG.MSG_EDITOR_ACTIVITY_SUCCESS: // 发布活动成功
                        if (StringUtil.isStrEmpty(activityId)) {
                            showToast("发布成功");
                            setResult(RESULT_OK);
                        } else {
                            showToast("修改成功");
                            setResult(RESULT_OK);
                        }
                        finish();
                        break;
                    case MSG.MSG_EDITOR_ACTIVITY_FIELD: // 发布活动失败
                        showToast(msg.obj.toString());
                        break;
                    case MSG.MSG_FILE_UPLOAD_SUCCESS:  // 上传图片
                        dismissDialog();
                        try {
                            String value = new org.json.JSONObject(msg.obj.toString()).getString("value");
                            imgPath=value;
                            if (select == -1) {

                            FrescoUtil.showImageSmall(value, ivImg);
                        } else {
                            imgs[select] = value;
                            FrescoUtil.showImageSmall(value, sdvArray[select]);
                        }


                        } catch (JSONException e) {
                            e.printStackTrace();
                        }


                        break;
                    case MSG.MSG_FILE_UPLOAD_FIELD:
                        dismissDialog();
                        showToast(msg.obj.toString());
                        break;
                }
            }
        }

        ;
    }

    @Override
    public void callBack(Object object) {

        typeList = FastJsonUtil.getListBeanRow(object.toString(), "options", ActivityTypeVO.class);


        initActivityType();
    }

    /**
     * 活动类型选择器
     */
    private void initActivityType() {

        if (typeList != null && typeList.size() > 0) {
            pvActivityType = new OptionsPickerView.Builder(AddActivityActivity.this, new OptionsPickerView.OnOptionsSelectListener() {
                @Override
                public void onOptionsSelect(int options1, int option2, int options3, View v) {
                    String select = typeList.get(options1).getPickerViewText();
                    tvType.setText(select);
                    code = typeList.get(options1).getValue();
                }
            })
                    .setSubCalSize(16)//确定取消按钮大小
                    .setLineSpacingMultiplier(1.5f) //设置两横线之间的间隔倍数（范围：1.2 - 2.0倍 文字高度）
                    .setDividerColor(getResources().getColor(R.color.colorFontLightGrayB))//设置分割线的颜色
                    .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                    .setContentTextSize(18)//设置滚轮文字大小
                    .setSelectOptions(0)  //设置默认选中项
                    .build();

            pvActivityType.setPicker(typeList);
        } else {
            showToast("正在获取活动类型");
            // 活动类型
            BusinessActivity.getActivityType(this, mHandler);
        }

    }

    /**
     * 所在区域选择
     */
    private void showAddressPicker() {
        final BottomDialog bottomDialog = new BottomDialog(AddActivityActivity.this);
        bottomDialog.setOnAddressSelectedListener(new OnAddressSelectedListener() {
            @Override
            public void onAddressSelected(Province province, City city, County county, Street street) {
                provinceName = province.province_name;
                provinceNameCode= province.province_code;
                cityName = city != null ? city.city_name : "";
                cityNameCode = city != null ? city.city_code : "";
                countyName = county != null ? county.county_name : "";
                countyNameCoee = county != null ? county.county_code : "";

                tvArea.setText(String.format("%s %s %s", provinceName, cityName
                        , countyName));
                bottomDialog.dismiss();
            }
        });
        bottomDialog.show();
    }

    @Override
    public void rightOnClick() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.tv_type, R.id.tv_start_date, R.id.tv_end_date, R.id.tv_start_date_process, R.id.tv_end_date_process, R.id.tv_area,
            R.id.iv_img, R.id.sdv_img0, R.id.sdv_img1, R.id.sdv_img2, R.id.sdv_img3, R.id.sdv_img4, R.id.sdv_img5, R.id.sdv_img6,
            R.id.sdv_img7, R.id.btn_save})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_type:
                if (pvActivityType != null)
                    pvActivityType.show();
                break;
            case R.id.tv_start_date:
                type = 0;
                pvTime.show();
                break;
            case R.id.tv_end_date:
                type = 1;
                pvTime.show();
                break;
            case R.id.tv_start_date_process:
                type = 2;
                pvTime.show();
                break;
            case R.id.tv_end_date_process:
                type = 3;
                pvTime.show();
                break;
            case R.id.tv_area:
                showAddressPicker();
                break;
            case R.id.iv_img:
                select = -1;
                Intent intent = new Intent(AddActivityActivity.this, ImageGridActivity.class);
                startActivityForResult(intent, REQUEST_CODE_SELECT);
                break;
            case R.id.sdv_img0:
                selectImage(0);
                break;
            case R.id.sdv_img1:
                selectImage(1);
                break;
            case R.id.sdv_img2:
                selectImage(2);
                break;
            case R.id.sdv_img3:
                selectImage(3);
                break;
            case R.id.sdv_img4:
                selectImage(4);
                break;
            case R.id.sdv_img5:
                selectImage(5);
                break;
            case R.id.sdv_img6:
                selectImage(6);
                break;
            case R.id.sdv_img7:
                selectImage(7);
                break;
            case R.id.btn_save:
                save();
                break;
        }
    }

    // 选择图片
    private void selectImage(int i) {
        select = i;
        if (StringUtil.isStrEmpty(imgs[select])) {
            Intent intent = new Intent(AddActivityActivity.this, ImageGridActivity.class);
            startActivityForResult(intent, REQUEST_CODE_SELECT);
        } else {
            new MaterialDialog.Builder(AddActivityActivity.this)
                    .title("提示")
                    .content("是否删除这张照片？")
                    .positiveText("删除")
                    .negativeText("取消")
                    .onPositive(new MaterialDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                            imgs[select] = "";
                            Uri uri = Uri.parse("res://com.digitalchina.bigdata/" + R.drawable.selector_image_add);
                            sdvArray[select].setImageURI(uri);
                        }
                    })
                    .show();
        }

    }


    /**
     * 跳转回调
     *
     * @param requestCode
     * @param resultCode
     * @param data
     */
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == ImagePicker.RESULT_CODE_ITEMS) {
            //添加图片返回
            if (data != null && requestCode == REQUEST_CODE_SELECT) {
                ArrayList<ImageItem> images = (ArrayList<ImageItem>) data.getSerializableExtra(ImagePicker.EXTRA_RESULT_ITEMS);
                if (images != null && images.size() > 0) {
                    showDialog("正在上传图片...");
                    BusinessFile.imageCompressAndUpload(this, images.get(0).path, mHandler);
                }
            }
        }

    }

    /**
     * 时间选择器
     * 0=报名开始  1=报名结束  2=活动开始  3=活动结束
     */
    private void initTimePicker() {

        int start = 2017;
        int endDate = 2100;

        //控制时间范围,setRange方法 要在setDate 之前才有效果(如果不设置范围，则使用默认时间1900-2100年，此段代码可注释)
        /*Calendar calendar = Calendar.getInstance();*/

        //时间选择器
        pvTime = new TimePickerView.Builder(this, new TimePickerView.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调

                String time = DateToString(date, DateStyle.YYYY_MM_DD_EN_HH_MM);

                switch (type) {
                    case 0:
                        tvStartDate.setText(time);
                        break;
                    case 1:
                        tvEndDate.setText(time);
                        break;
                    case 2:
                        tvStartDateProcess.setText(time);
                        break;
                    case 3:
                        tvEndDateProcess.setText(time);
                        break;
                }

            }
        })
                .setType(TimePickerView.Type.YEAR_MONTH_DAY_HOURS_MINS)//default is all
                .setLabel("年", "月", "日", ":", "", "") //设置空字符串以隐藏单位提示   hide label
                .setRange(start, endDate)
                .build();
    }

    // 发布活动
    private void save() {
        activityName = etName.getText().toString();
        if (StringUtil.isStrEmpty(activityName)) {
            showToast("请填写活动名称");
            return;
        }
        if (StringUtil.isStrEmpty(code)) {
            showToast("请选择活动类型");
            return;
        }
        if (isRegister.equals("0")) {
            registerStartTime = "";
            registerDeadline = "";
        } else {
            registerStartTime = tvStartDate.getText().toString();
            registerDeadline = tvEndDate.getText().toString();
            if (StringUtil.isStrEmpty(registerStartTime)) {
                showToast("请选择报名开始时间");
                return;
            }
            if (StringUtil.isStrEmpty(registerDeadline)) {
                showToast("请选择报名结束时间");
                return;
            }
        }
        startTime = tvStartDateProcess.getText().toString();
        if (StringUtil.isStrEmpty(startTime)) {
            showToast("请选择活动开始时间");
            return;
        }
        endTime = tvEndDateProcess.getText().toString();
        if (StringUtil.isStrEmpty(endTime)) {
            showToast("请选择活动结束时间");
            return;
        }

        if (StringUtil.isStrEmpty(tvArea.getText().toString())) {
            showToast("请选择所在区域");
            return;
        }
        address = etDetailAddress.getText().toString();
        if (StringUtil.isStrEmpty(address)) {
            showToast("请填写详细地址");
            return;
        }
        if (isFee.equals("0")) {
            fee = "0.0";
        } else {
            fee = etPrice.getText().toString();
            if (StringUtil.isStrEmpty(fee)) {
                showToast("请输入费用");
                return;
            }
        }
        if (isLimit.equals("0")) {
            num = "";
        } else {
            num = etNum.getText().toString();
            if (StringUtil.isStrEmpty(num)) {
                showToast("请输入限制人数");
                return;
            }
        }
        sponsorName = etZbfName.getText().toString();
        if (StringUtil.isStrEmpty(sponsorName)) {
            showToast("请填写主办方名称");
            return;
        }
        sponsorPerson = etZbfContacts.getText().toString();
        if (StringUtil.isStrEmpty(sponsorPerson)) {
            showToast("请填写主办方联系人");
            return;
        }
        sponsorTel = etZbfTel.getText().toString();
        if (StringUtil.isStrEmpty(sponsorTel)) {
            showToast("请填写主办方联系方式");
            return;
        }
        organizerName = etCbfName.getText().toString();
//        if (StringUtil.isStrEmpty(organizerName)) {
//            showToast("请填写承办方名称");
//            return;
//        }
        organizerPerson = etCbfContacts.getText().toString();
        if (StringUtil.isStrEmpty(organizerPerson)) {
            showToast("请填写承办方联系人");
            return;
        }
        organizerTel = etCbfTel.getText().toString();
//        if (StringUtil.isStrEmpty(organizerTel)) {
//            showToast("请填写承办方联系方式");
//            return;
//        }
        if (StringUtil.isStrEmpty(imgPath)) {
            showToast("请上传海报");
            return;
        }
        activityIntroduce = etInfo.getText().toString();
        if (StringUtil.isStrEmpty(activityIntroduce)) {
            showToast("请填写活动介绍");
            return;
        }

//        List<ImageVO> imageVOList = new ArrayList<>();
//
//        for (String img : imgs) {
//            if (!StringUtil.isStrEmpty(img)) {
//                ImageVO im = new ImageVO();
//                im.setImage(img);
//                imageVOList.add(im);
//            }
//        }

      //  subjectActivityDescImageList = JSON.toJSONString(imageVOList, true);

        if("".equals(activityId)){
            BusinessActivity.saveActivity(this, activityName, code, isRegister, registerStartTime, registerDeadline, startTime,
                    endTime, provinceNameCode, cityNameCode, countyNameCoee, address, isFee, Utils.formatPrice(fee), isLimit, num, activityIntroduce, sponsorName, sponsorPerson,
                    sponsorTel, organizerName, organizerPerson, organizerTel, imgPath, activityId, subjectActivityDescImageList, mHandler);

        }else{

            BusinessActivity.editorActivity(this, activityName, code, isRegister, registerStartTime, registerDeadline, startTime,
                    endTime, provinceNameCode, cityNameCode, countyNameCoee, address, isFee, Utils.formatPrice(fee), isLimit, num, activityIntroduce, sponsorName, sponsorPerson,
                    sponsorTel, organizerName, organizerPerson, organizerTel, imgPath, activityId, subjectActivityDescImageList, mHandler);


        }


    }
}